﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sector7.Framework.Core;
using Sector7.Medical.Events;
using Sector7.Medical.Consts;

namespace Sector7.Medical.Controls
{
    /// <summary>
    /// NavigationContainer.xaml 的交互逻辑
    /// </summary>
    public partial class NavigationHeader : UserControl
    {
        #region Accessor
        public event ExpandedChangeEventHandler ExpandedChange = null;

        public event ClickNavigationItemEventHandler ClickNavigationItem = null;
        #endregion

        #region Public functions
        public void InitializeControl(NavigationConfiguration navigationConfiguration)
        {
            m_navigationConfig = navigationConfiguration;

            lblCaption.Content = navigationConfiguration.Caption;
            if (navigationConfiguration.Items != null)
            {
                lblExpand.Content = C_ControlSymbol.EXPAND;
                lblExpand.Visibility = Visibility.Visible;
            }
        }
        #endregion

        #region Private functions
        private void OnClickNavigationItem(object sender, ClickNavigationItemEventArgs e)
        {
            if (ClickNavigationItem != null)
            {
                ClickNavigationItem(sender, e);
            }
        }

        private void OnExpandedChange(object sender, ExpandedChangeEventArgs e)
        {
            if (ExpandedChange != null)
            {
                ExpandedChange(sender, e);
            }
        }

        private void Caption_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            bool isExpand = false;
            switch (lblExpand.Content.ToString())
            {
                case C_ControlSymbol.EXPAND:
                    isExpand = true;
                    lblExpand.Content = C_ControlSymbol.COLLAPSE;
                    break;
                case C_ControlSymbol.COLLAPSE:
                    isExpand = false;
                    lblExpand.Content = C_ControlSymbol.EXPAND;
                    break;
                default:
                    break;
            }

            OnExpandedChange(this, new ExpandedChangeEventArgs(isExpand, 0));
            if (m_navigationConfig.ModuleId != null && m_navigationConfig.ClassName != null)
            {
                OnClickNavigationItem(this, new ClickNavigationItemEventArgs(m_navigationConfig));
            }
        }
        #endregion

        #region Structure
        public NavigationHeader()
        {
            InitializeComponent();
        }
        #endregion

        #region Inner members
        private NavigationConfiguration m_navigationConfig = null;
        #endregion
    }
}
